var wxShareConf = {
    getOpenIDAddr:"https://api.weixin.qq.com/sns/jscode2session?appid=wx529d0ca931723a22&secret=a19b17acac2fe97d7b0ccbd6ec245748&js_code=", //传入code获取微信openID的服务端地址
    //             https://api.weixin.qq.com/sns/jscode2session?appid=wx529d0ca931723a22&secret=a19b17acac2fe97d7b0ccbd6ec245748&js_code=021l2xwS0WsR0Y1C6IwS07FswS0l2xwb&grant_type=authorization_code
    last_code:"&grant_type=authorization_code"
}

/**
 * 获取启动参数
 */
function getLaunchOptionsSync() {
    var LaunchOption = wx.getLaunchOptionsSync();
    console.log("LaunchOption:" + JSON.stringify(LaunchOption));
    console.log("LaunchOption quary:" + JSON.stringify(LaunchOption.query));
    return LaunchOption;
}

/**
 * 约战API
 * @param {string} title 
 * @param {string} query getLaunchOptionsSync 中的参数
 */
function together(title, query) {
    wx.shareAppMessage({
        title: title,
        query: query,
        complete: function () {
            console.log(arguments);
        },
        success: function (shareTickets, groupMsgInfos) {
            console.log(shareTickets);
            console.log(groupMsgInfos);
        }
    })

    wx.updateShareMenu({
        withShareTicket: true,//开启群发
        success: function () {
            console.log("updateShareMenu success");
        },
        fail: function (e) {
            console.log("updateShareMenu fail" + e);
        }
    });


}

/**
 * 获取用户信息
 */
function getWxUserInfo(data) {
    wx.getUserInfo({
        openIdList: ['selfOpenId'],
        lang: 'zh_CN',
        success: function (res) {
            console.log('success', res.userInfo);
            return data(res.userInfo);
        },
        fail: function (res) {
            reject(res);
            console.log("fail", res);
            return '';
        }});

}


/**
 * 获取用户OpenID
 */
function getUserOpenID(obj) {
    var callObj = obj;
    wx.login({
        success: function (res1) {
            var wcode = res1.code;
            //https://api.weixin.qq.com/sns/jscode2session?appid=wx529d0ca931723a22&secret=a19b17acac2fe97d7b0ccbd6ec245748&js_code=021l2xwS0WsR0Y1C6IwS07FswS0l2xwb&grant_type=authorization_code
            console.log("获取openid地址:"+wxShareConf.getOpenIDAddr+wcode+wxShareConf.last_code);
            wx.request({
                url: wxShareConf.getOpenIDAddr+wcode+wxShareConf.last_code,
                method: "GET",
                data: {
                    code: wcode
                },
                success: function (res2) {
                    return callObj(res2);
                }
            });
            
        },
        fail: function (res) {
            obj.fail(res);
            console.log(res.data);
            return obj(res.data);
        },
    });
}



window.getLaunchOptionsSync = getLaunchOptionsSync;
window.together = together;
window.getWxUserInfo = getWxUserInfo;
window.getUserOpenID = getUserOpenID;